package
{
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class Util
	{
		public function Util()
		{
		}
		
		public static function getNormalizedDistance(src:Point, dest:Point, factor:Number):Point{
			var pnt:Point = dest.subtract(src);
			pnt.normalize(factor);
			return pnt;
		}
		
		public static function clampPoint(point:Point, size:Number):Point{
			var clamped:Point = new Point(Math.floor(point.x/size) * size, Math.floor(point.y/size) * size);
			return clamped;
		}
		
		public static function center(dispObj:DisplayObject, horiz:Boolean = true, vert:Boolean = true):void{
			
			if(horiz){
				dispObj.x = dispObj.parent.width/2 - dispObj.width/2;
			}
			
			if(vert){
				dispObj.y = dispObj.parent.height/2 - dispObj.height/2;
			}
		}
		
		public static function getCircle(color:uint, radius:Number):Sprite{
			var circ:Sprite = new Sprite();
			circ.graphics.lineStyle(1);
			circ.graphics.beginFill(color);
			circ.graphics.drawCircle(0,0,radius);
			circ.graphics.endFill();
			return circ;
		}
		
		public static function getRect(width:Number, height:Number,color:uint=0xffffff, lineThickness:Number = 1):Sprite{
			var rect:Sprite = new Sprite();
			rect.graphics.lineStyle(lineThickness);
			rect.graphics.beginFill(color);
			rect.graphics.drawRect(0,0,width,height);
			rect.graphics.endFill();
			return rect;
		}
		
		public static function getGrid(dimensions:Point, cellSize:int, optional:Object=null):Sprite{
			var grid:Sprite = new Sprite();
			var i:int, il:int, j:int, jl:int;
			var g:Graphics = grid.graphics;
			g.lineStyle(1);
			g.drawRect(0,0,dimensions.x*cellSize, dimensions.y*cellSize);
			for(i = 0; i < dimensions.x; i ++){
				g.moveTo(i*cellSize,0);
				g.lineTo(i*cellSize,dimensions.y*cellSize);
			}
			
			for(i = 0; i < dimensions.y; i ++){
				g.moveTo(0,i*cellSize);
				g.lineTo(dimensions.x*cellSize,i*cellSize);
			}
			
			return grid;
		}
	}
}